package com.junmeng.libfloating.ball

import com.junmeng.libfloating.R

class PanelConfig {
    companion object {
        @JvmStatic
        fun newBuilder(father: SimpleFloatingViewFactory.Builder): Builder {
            return Builder(father)
        }
    }

    class Builder(private var father: SimpleFloatingViewFactory.Builder) {

        var layoutResId: Int = R.layout.floating_panel

        var dingResIds: Array<Int> = arrayOf(
            R.drawable.floating_ic_round_push_pin_24_unselected,
            R.drawable.floating_ic_round_push_pin_24_selected
        )

        var widthRatio: Float = 0.8f
        var heightMaxRatio: Float = 0.7f

        var tabBarBackground: Int = R.color.floating_panel_bg
        var tabContentBackground: Int = R.color.floating_panel_bg

        var tabs: ArrayList<IPanelTab> = arrayListOf()
        var canDragOverEdge: Boolean = false

        var supportScale = true

        /**
         * 是否可以拖拽出边界，默认false
         */
        fun canDragOverEdge(canDragOverEdge: Boolean): Builder {
            this.canDragOverEdge = canDragOverEdge
            return this
        }

        /**
         * 是否支持缩放功能
         * @param enable Boolean
         * @return Builder
         */
        fun supportScale(enable: Boolean): Builder {
            supportScale = enable
            return this
        }

        /**
         * 自定义面板视图,用户可以参照R.layout.floating_simple_panel进行修改，唯一不能修改的是控件(例如不能把ImageView改为TextView)和控件id
         */
        fun viewResId(layoutResId: Int): Builder {
            this.layoutResId = layoutResId
            return this
        }

        /**
         * 如果ratio小于1，则表示面板宽度占屏幕宽度的比例，默认0.8,如果ratio大于1，则表示面板宽度
         */
        fun widthRatio(ratio: Float): Builder {
            this.widthRatio = ratio
            return this
        }

        /**
         * 如果ratio小于1，则表示面板高度占屏幕高度的比例，默认0.7,如果ratio大于1，则表示面板高度
         */
        fun heightMaxRatio(ratio: Float): Builder {
            this.heightMaxRatio = ratio
            return this
        }

        /**
         * 固定面板按钮的选中/未选状态图标数组，下标0表示未固定时的图标，下标1表示固定后的图标
         */
        fun dingResIds(dingResIds: Array<Int>): Builder {
            if (dingResIds.size != 2) {
                return this
            }
            this.dingResIds = dingResIds
            return this
        }

        /**
         * tab栏的背景颜色
         */
        fun tabBarBackground(bgResId: Int): Builder {
            this.tabBarBackground = bgResId
            return this
        }

        /**
         * tab内容区的背景颜色
         */
        fun tabContentBackground(bgResId: Int): Builder {
            this.tabContentBackground = bgResId
            return this
        }

        /**
         * 注册tab
         */
        fun registerTab(tab: IPanelTab): Builder {
            if (this.tabs.contains(tab)) {
                return this
            }
            this.tabs.add(tab)
            return this
        }

        /**
         * 注册多个tab
         */
        fun registerTabs(tabs: List<IPanelTab>): Builder {
            this.tabs.addAll(tabs)
            return this
        }

        /**
         * 完成配置
         */
        fun finish(): SimpleFloatingViewFactory.Builder {
            return father
        }
    }


}